#define _CRT_SECURE_NO_WARNINGS 1
#include<limits.h>
#include<math.h>
int flipgame(int* fronts, int frontsSize, int* backs, int backsSize) {
    int F[2001] = { 0 };
    for (int i = 0; i < frontsSize; i++) {
        if (fronts[i] == backs[i])F[fronts[i]] = 1;
    }
    int ans = INT_MAX;
    for (int i = 0; i < frontsSize; i++) {
        if (!F[backs[i]])ans = fmin(ans, backs[i]);
        if (!F[fronts[i]])ans = fmin(ans, fronts[i]);
    }
    return ans == INT_MAX ? 0 : ans;
}